package com.njzxw.fs.serverAdmin;

import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
import de.codecentric.boot.admin.server.notify.Notifier;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.time.Duration;
import java.util.List;

@Configuration
public class NotifierConfig {

    @Autowired
    private Notifier notifier;

    private final InstanceRepository repository;
    private final ObjectProvider<List<Notifier>> otherNotifiers;

    public NotifierConfig(InstanceRepository repository, ObjectProvider<List<Notifier>> otherNotifiers) {
        this.repository = repository;
        this.otherNotifiers = otherNotifiers;
    }


    @Primary
    @Bean(initMethod = "start", destroyMethod = "stop")
    public DdNotifier remindingNotifier() {
        DdNotifier notifier_ = new DdNotifier(notifier, repository);
        notifier_.setReminderPeriod(Duration.ofMinutes(10));
        notifier_.setCheckReminderInverval(Duration.ofSeconds(10));
        return notifier_;
    }

}
